package com.lambada.test1;

import java.util.*;
import java.util.stream.Collectors;

public class ListTest {


    public static void main(String[] args) {
        ListTest test = new ListTest();
        List<Account> list = new ArrayList<>();
        list.add(new Account(1,"zhangsan"));
        list.add(new Account(2,"li"));
        Map<Integer, String> map = test.listToMap(list);


        map.entrySet().stream().forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));



    }



    public void test1() {

        List<String> list = new ArrayList<>();//新建一个List 用的google提供的Guava  package com.google.common.collect;
        list.add("1");
        list.add("2");
        list.add("3");

        for (String string : list) {
            System.out.println(string);
        }
    }


    public void test2() {
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        list1.add("1");
        list1.add("2");
        list1.add("3");

        list2 = list1.stream().map(string -> {
            return "stream().map()处理之后：" + string;
        }).collect(Collectors.toList());

        list2.stream().forEach(string -> {
            System.out.println(string);
        });
    }


    public Map<Integer, String> listToMap(List<Account> accounts) {
        Map<Integer, String> map = accounts.stream().collect(Collectors.toMap(Account::getId, Account::getName));
        return  map;
    }



    static class Account {
        public  Account(int id,String name){
            this.id=id;
            this.name=name;
        }
        int id;
        String name;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }


}
